﻿using CsharpTrainer.Linq;
using System.Data.Linq;
using System.Configuration;

namespace CsharpTrainer.Linq.Service
{
    public class BaseService<TEntity>
        where TEntity : class
    {
        //  由private 改成 protected ，子类可通过此访问数据库连接，用于存储过程方法。
        protected readonly DataContext _context = null;
        protected IRepository<TEntity> _session = null;
        private readonly DataContext _contextAmany = null;
        protected IRepository<TEntity> _sessionAmany = null;
        protected BaseService()
        {
            _context = new DataContext(ConfigurationManager.ConnectionStrings["NorthwindConnStr"].ToString());
            _session = new LinqRepository<TEntity>(_context);
            _contextAmany = new DataContext(ConfigurationManager.ConnectionStrings["NorthwindConnStr"].ToString());
            _sessionAmany = new LinqRepository<TEntity>(_contextAmany);
        }
    }
}
